#include "../../../../mac/timer.h"

static uint8 cnt = 0;
static uint8 max_cnt;
static void callback(int signum);

int32 timer_get_test()
{
    return timer_get();
}

int8 timer_start_test(int8 num)
{
    mtimer_t timer;
    uint32 t, now;

    t = timer_get();

    MAC_DEBUG("timer_start_test: 1\n");
    max_cnt = num;
    timer.func = callback;
    timer.expire = 40000;
    timer_start(&timer, timer.expire);

    MAC_DEBUG("timer_start_test: 2\n");
    /* delay for a while to give the timer time to time out. */
    while(now = timer_get()) {
        if ((int32)(now - t) > 1500000) {
            break;
        }
    }

    return MAC_OK;
}

static void callback(int signum)
{
    mtimer_t timer;
    if (cnt >= max_cnt) {
        return;
    }

    cnt++;
    MAC_DEBUG("cnt = %d\n", cnt);
    timer.func = callback;
    timer.expire = 40000;
    timer_start(&timer, timer.expire);
}

uint8 get_cnt_test()
{
    return cnt;
}

uint8 reset_cnt_test()
{
    cnt = 0;
}


